<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>城会玩 - 登录</title>
     <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="/static/js/jquery_2.1.4_jquery.min.js"></script>
    <!-- BootStrap -->
    <script src="/static/js/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="/static/js/bootstrap-3.4.1-dist/css/bootstrap.min.css">
    <style>
        :root {
            --primary: #FF6B35;
            --primary-dark: #e55a2b;
            --primary-light: rgba(255, 107, 53, 0.1);
            --secondary: #2A9D8F;
            --light: #F8F9FA;
            --dark: #343A40;
            --accent: #E9C46A;
            --gradient-primary: linear-gradient(135deg, #FF6B35 0%, #FF8E53 100%);
            --gradient-secondary: linear-gradient(135deg, #2A9D8F 0%, #44C2B3 100%);
            --gradient-hero: linear-gradient(135deg, rgba(255, 107, 53, 0.92) 0%, rgba(233, 196, 106, 0.85) 100%);
            --shadow: 0 10px 30px rgba(0,0,0,0.1);
            --shadow-hover: 0 15px 40px rgba(0,0,0,0.15);
            --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            overflow-x: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .login-container {
            width: 100%;
            max-width: 1000px;
            display: grid;
            grid-template-columns: 1fr 1fr;
            min-height: 600px;
            border-radius: 24px;
            overflow: hidden;
            box-shadow: var(--shadow-hover);
            animation: fadeInUp 0.8s ease-out forwards;
            opacity: 0;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .hero-section {
            background: var(--gradient-hero);
            color: white;
            padding: 3rem 2.5rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        .hero-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 100" fill="rgba(255,255,255,0.1)"><polygon points="1000,100 1000,0 0,100"/></svg>');
            background-size: cover;
        }

        .hero-content {
            position: relative;
            z-index: 2;
        }

        .hero-title {
            font-size: 40px;
            font-weight: 700;
            margin-bottom: 1rem;
            line-height: 1.2;
        }

        .hero-subtitle {
            font-size: 14px;
            margin-bottom: 2rem;
            opacity: 0.9;
            line-height: 1.6;
        }

        .features-grid {
            display: grid;
            gap: 1rem;
            margin-top: 2rem;
        }

        .feature-item {
            display: flex;
            align-items: center;
            gap: 1rem;
            padding: 0.75rem;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 12px;
            backdrop-filter: blur(10px);
            transition: var(--transition);
        }

        .feature-item:hover {
            background: rgba(255, 255, 255, 0.15);
            transform: translateX(5px);
        }

        .feature-icon {
            width: 40px;
            height: 40px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .feature-text h3 {
            margin: 0 0 0.25rem 0;
            font-size: 20px;
        }

        .feature-text p {
            margin: 0;
            font-size: 14px;
            opacity: 0.8;
        }

        .form-section {
            background: white;
            padding: 3rem 3rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        .form-header {
            text-align: center;
            margin-bottom: 2rem;
        }

        .form-title {
            font-size: 30px;
            font-weight: 600;
            color: var(--dark);
            margin-bottom: 0.5rem;
        }

        .form-subtitle {
            color: #6c757d;
            font-size: 14px;
        }

        .form-group {
            margin-bottom: 3rem;
            position: relative;
        }

        .input-with-icon {
            position: relative;
        }

        .input-icon {
            position: absolute;
            left: 16px;
            top: 50%;
            transform: translateY(-50%);
            color: #6c757d;
            z-index: 2;
            transition: var(--transition);
        }

        .form-control {
            border: 2px solid #e9ecef;
            border-radius: 12px;
            padding: 8px 12px 8px 40px;
            font-size: 14px;
            transition: var(--transition);
            background: #fafbfc;
            width: 300px;
            font-family: inherit;
            height: 44px;
        }

        .form-control:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px var(--primary-light);
            background: white;
            outline: none;
        }

        .form-control:focus ~ .input-icon {
            color: var(--primary);
        }

        .btn-login {
            background: var(--gradient-primary);
            border: none;
            border-radius: 12px;
            padding: 12px;
            font-weight: 600;
            font-size: 14px;
            width: 300px;
            margin: 1.2rem 0 0.8rem;
            transition: var(--transition);
            color: white;
            cursor: pointer;
            font-family: inherit;
            position: relative;
            overflow: hidden;
            height: 46px;
        }

        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(255, 107, 53, 0.3);
        }

        .auth-links {
            display: flex;
            justify-content: space-between;
            margin-top: 1.5rem;
            padding-top: 1.5rem;
            border-top: 1px solid #e9ecef;
        }

        .auth-link {
            color: var(--primary);
            text-decoration: none;
            font-weight: 500;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-size: 15px;
        }

        .auth-link:hover {
            color: var(--primary-dark);
            transform: translateX(3px);
        }

        .alert-message {
            border-radius: 12px;
            margin: 1rem 0;
            padding: 0.8rem 1rem;
            text-align: center;
            border: none;
            font-weight: 500;
            animation: fadeIn 0.5s ease-out forwards;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .particles-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
            z-index: 1;
        }

        /* 重置密码表单样式 */
        .reset-password-form {
            display: none;
        }

        .verify-code-group {
            display: flex;
            gap: 10px;
            position: relative;
            width: 300px;
            margin: 0 auto;
        }

        .verify-code-input {
            flex: 1;
        }

        .send-code-btn {
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 8px;
            padding: 0 12px;
            white-space: nowrap;
            transition: var(--transition);
            font-weight: 500;
            cursor: pointer;
            font-size: 12px;
            height: 32px;
            position: absolute;
            right: 6px;
            top: 50%;
            transform: translateY(-50%);
            z-index: 3;
            min-width: 90px;
        }

        .send-code-btn:hover:not(:disabled) {
            background: var(--primary-dark);
            transform: translateY(-50%) scale(1.05);
            box-shadow: 0 3px 10px rgba(255, 107, 53, 0.2);
        }

        .send-code-btn:disabled {
            background: #6c757d;
            cursor: not-allowed;
            transform: translateY(-50%);
            box-shadow: none;
        }

        .back-to-login {
            text-align: center;
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #e9ecef;
        }

        .back-to-login a {
            color: var(--primary);
            text-decoration: none;
            font-weight: 500;
            transition: var(--transition);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
        }

        .back-to-login a:hover {
            color: var(--primary-dark);
            transform: translateX(-3px);
        }

        /* 为验证码输入框增加右侧内边距 */
        .verify-code-group .form-control {
            padding-right: 100px;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            body {
                padding: 10px;
                align-items: flex-start;
            }

            .login-container {
                grid-template-columns: 1fr;
                max-width: 500px;
                min-height: auto;
            }

            .hero-section {
                padding: 2rem 1.5rem;
                order: 2;
            }

            .form-section {
                padding: 2rem 1.5rem;
                order: 1;
            }

            .hero-title {
                font-size: 32px;
            }

            .features-grid {
                grid-template-columns: 1fr;
            }

            .auth-links {
                flex-direction: column;
                gap: 1rem;
                text-align: center;
            }

            .verify-code-group {
                flex-direction: column;
            }

            .send-code-btn {
                position: relative;
                width: 100%;
                margin-top: 10px;
                transform: none;
            }

            .verify-code-group .form-control {
                padding-right: 12px;
            }
        }

        @media (max-width: 480px) {
            .hero-section, .form-section {
                padding: 1.5rem 1rem;
            }

            .hero-title {
                font-size: 28px;
            }

            .form-title {
                font-size: 24px;
            }

            .form-control {
                width: 280px;
            }

            .btn-login {
                width: 280px;
            }
        }

        /* 自定义通知样式 */
        .custom-notification {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1050;
            animation: slideInRight 0.3s ease-out forwards;
            border-radius: 12px;
            padding: 1rem 1.25rem;
            border: none;
            font-weight: 500;
            max-width: 300px;
        }

        @keyframes slideInRight {
            from {
                opacity: 0;
                transform: translateX(100%);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        @keyframes slideOutRight {
            from {
                opacity: 1;
                transform: translateX(0);
            }
            to {
                opacity: 0;
                transform: translateX(100%);
            }
        }



        /* QQ登录相关样式 */
        .social-login {
            margin: 1.5rem 0;
            text-align: center;
        }

        .divider {
            position: relative;
            margin: 1.5rem 0;
            text-align: center;
        }

        .divider::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: #e9ecef;
            z-index: 1;
        }

        .divider span {
            background: white;
            padding: 0 1rem;
            position: relative;
            z-index: 2;
            color: #6c757d;
            font-size: 14px;
        }

        .btn-qq-login {
            background: #12B7F5;
            border: none;
            border-radius: 12px;
            padding: 12px;
            font-weight: 600;
            font-size: 14px;
            width: 300px;
            transition: var(--transition);
            color: white;
            cursor: pointer;
            font-family: inherit;
            position: relative;
            overflow: hidden;
            height: 46px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn-qq-login:hover {
            background: #0F9CD9;
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(18, 183, 245, 0.3);
        }

        /* QQ登录弹窗样式 */
        .qq-login-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 9999;
            align-items: center;
            justify-content: center;
        }

        .qq-login-content {
            background: white;
            border-radius: 16px;
            padding: 2rem;
            text-align: center;
            max-width: 400px;
            width: 90%;
            box-shadow: var(--shadow-hover);
            animation: fadeInUp 0.3s ease-out;
        }

        .qq-login-header {
            margin-bottom: 1.5rem;
        }

        .qq-login-header h3 {
            color: var(--dark);
            margin-bottom: 0.5rem;
            font-size: 1.5rem;
        }

        .qq-login-header p {
            color: #6c757d;
            font-size: 14px;
        }

        .qrcode-container {
            margin: 1.5rem 0;
            padding: 1rem;
            background: #f8f9fa;
            border-radius: 12px;
            display: inline-block;
        }

        #qqLoginQrcode {
            width: 200px;
            height: 200px;
        }

        .qq-login-status {
            margin: 1rem 0;
            padding: 0.75rem;
            border-radius: 8px;
            font-size: 14px;
            display: none;
        }

        .qq-login-status.success {
            background: var(--primary-light);
            color: var(--primary);
            border: 1px solid var(--primary);
        }

        .qq-login-status.error {
            background: rgba(220, 53, 69, 0.1);
            color: #dc3545;
            border: 1px solid #dc3545;
        }

        .qq-login-footer {
            margin-top: 1.5rem;
            padding-top: 1.5rem;
            border-top: 1px solid #e9ecef;
        }

        .qq-login-footer p {
            color: #6c757d;
            font-size: 12px;
            margin: 0.5rem 0;
        }

        .btn-close-modal {
            background: #6c757d;
            color: white;
            border: none;
            border-radius: 8px;
            padding: 0.5rem 1rem;
            cursor: pointer;
            font-size: 14px;
            transition: var(--transition);
        }

        .btn-close-modal:hover {
            background: #5a6268;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <!-- 左侧英雄区域 -->
        <div class="hero-section">
            <div class="particles-container" id="particles"></div>
            <div class="hero-content">
                <h1 class="hero-title">加入城会玩</h1>
                <p class="hero-subtitle">注册账号，开启精彩的本地社交生活，与志同道合的朋友相遇</p>

                <div class="features-grid">
                    <div class="feature-item">
                        <div class="feature-icon">
                            📅
                        </div>
                        <div class="feature-text">
                            <h3>活动丰富</h3>
                            <p>每日更新各类本地活动，总有你感兴趣的</p>
                        </div>
                    </div>
                    <div class="feature-item">
                        <div class="feature-icon">
                            👥
                        </div>
                        <div class="feature-text">
                            <h3>活跃社区</h3>
                            <p>与志同道合的朋友交流分享，拓展社交圈</p>
                        </div>
                    </div>
                    <div class="feature-item">
                        <div class="feature-icon">
                            📍
                        </div>
                        <div class="feature-text">
                            <h3>本地推荐</h3>
                            <p>基于位置推荐最适合你的活动和场所</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 右侧表单区域 -->
        <div class="form-section">
            <div class="form-header">
                <h1 class="form-title"><i class="fas fa-sign-in-alt me-2"></i>邮箱登录</h1>
                <p class="form-subtitle">请使用注册邮箱登录您的账号</p>
            </div>

            <!-- 登录表单 -->
            <form class="auth-form" action="/user/login/" method="post" id="loginForm">
                {% csrf_token %}

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="email" class="form-control" id="inputEmail"
                               placeholder="请输入注册邮箱地址" name="email" required>
                        <span class="input-icon">📧</span>
                        <i class="fas fa-envelope input-icon"></i>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="password" class="form-control" id="inputPassword"
                               placeholder="请输入登录密码" name="password" required
                               minlength="6">
                        <span class="input-icon">🔒</span>
                        <i class="fas fa-lock input-icon"></i>
                    </div>
                </div>

                {% if error_message %}
                    <div class="alert alert-danger alert-message">
                        <i class="fas fa-exclamation-circle me-2"></i>{{ error_message }}
                    </div>
                {% endif %}
                {% if success_message %}
                    <div class="alert alert-success alert-message">
                        <i class="fas fa-check-circle me-2"></i>{{ success_message }}
                    </div>
                {% endif %}

                <!-- 重置密码成功消息显示区域 -->
                <div id="reset-success-message" class="alert alert-success alert-message" style="display: none;">
                    <i class="fas fa-check-circle me-2"></i><span id="reset-success-text"></span>
                </div>

                <button type="submit" class="btn-login" id="loginBtn">
                    <i class="fas fa-rocket me-2"></i>立即登录
                </button>

                <!-- 添加QQ登录按钮 -->
                <div class="social-login">
                    <div class="divider">
                        <span>或使用以下方式登录</span>
                    </div>
                    <button type="button" class="btn-qq-login" id="qqLoginBtn">
                        <i class="fab fa-qq me-2"></i>QQ扫码登录
                    </button>
                </div>


                <div class="auth-links">
                    <a href="/user/register/" class="auth-link">
                        <i class="fas fa-user-plus me-1"></i>注册新账号
                    </a>
                    <a href="#" id="show-reset-password" class="auth-link">
                        <i class="fas fa-key me-1"></i>忘记密码？
                    </a>
                </div>
            </form>

            <!-- 重置密码表单 -->
            <form class="reset-password-form" action="/user/login/" method="post" id="resetPasswordForm">
                {% csrf_token %}

                <input type="hidden" name="reset_email" value="1">
                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="email" class="form-control" id="reset-email"
                               placeholder="请输入注册邮箱地址" name="email" required>
                        <span class="input-icon">📧</span>
                        <i class="fas fa-envelope input-icon"></i>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-with-icon verify-code-group">
                        <input type="text" class="form-control verify-code-input"
                               id="verify-code" placeholder="6位验证码"
                               name="verify_code" required maxlength="6">
                        <span class="input-icon">✨</span>
                        <i class="fas fa-shield-alt input-icon"></i>
                        <button type="button" class="send-code-btn" id="send-code-btn">
                            发送验证码
                        </button>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="password" class="form-control" id="new-password"
                               placeholder="设置新密码" name="new_password" required>
                        <span class="input-icon">🔒</span>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-with-icon">
                        <input type="password" class="form-control" id="confirm-new-password"
                               placeholder="确认新密码" name="confirm_password" required>
                        <span class="input-icon">🔒</span>
                    </div>
                </div>

                {% if reset_error_message %}
                    <div class="alert alert-danger alert-message">
                        <i class="fas fa-exclamation-circle me-2"></i>{{ reset_error_message }}
                    </div>
                {% endif %}
                {% if reset_success_message %}
                    <div class="alert alert-success alert-message">
                        <i class="fas fa-check-circle me-2"></i>{{ reset_success_message }}
                    </div>
                {% endif %}

                <button type="submit" class="btn-login" id="resetPasswordBtn">
                    <i class="fas fa-redo me-2"></i>重置密码
                </button>

                <div class="back-to-login">
                    <a href="#" id="back-to-login">
                        <i class="fas fa-arrow-left me-1"></i>返回登录
                    </a>
                </div>
            </form>
        </div>
    </div>

    <script>
           document.addEventListener('DOMContentLoaded', function() {
            // 创建粒子背景
            function createParticles() {
                const container = document.getElementById('particles');
                const particleCount = 15;

                for (let i = 0; i < particleCount; i++) {
                    const particle = document.createElement('div');
                    particle.className = 'particle';
                    particle.style.cssText = `
                        position: absolute;
                        background: rgba(255,255,255,0.6);
                        border-radius: 50%;
                        animation: float ${Math.random() * 4 + 4}s ease-in-out infinite;
                        opacity: 0;
                        width: ${Math.random() * 6 + 2}px;
                        height: ${Math.random() * 6 + 2}px;
                        left: ${Math.random() * 100}%;
                        top: ${Math.random() * 100}%;
                        animation-delay: ${Math.random() * 5}s;
                    `;

                    setTimeout(() => {
                        particle.style.opacity = Math.random() * 0.4 + 0.2;
                    }, Math.random() * 1000);

                    container.appendChild(particle);
                }
            }

            createParticles();

            // 表单自动聚焦
            const emailInput = document.getElementById('inputEmail');
            if (emailInput) {
                setTimeout(() => {
                    emailInput.focus();
                }, 500);
            }

            // 检查重置密码成功状态
            function checkResetSuccess() {
                // 检查是否有重置成功的消息
                const resetSuccessElements = document.querySelectorAll('.alert-success');
                resetSuccessElements.forEach(element => {
                    const text = element.textContent || element.innerText;
                    if (text.includes('密码重置成功') || text.includes('reset_success')) {
                        // 自动切换到登录表单
                        showLoginForm();
                        // 显示成功消息
                        showNotification('密码重置成功！请使用新密码登录。', 'success');
                    }
                });
            }

            // 页面加载时检查重置密码成功状态
            checkResetSuccess();

            // 显示登录表单函数
            function showLoginForm() {
                const loginFormElement = document.querySelector('.auth-form');
                const resetPasswordForm = document.querySelector('.reset-password-form');

                if (loginFormElement && resetPasswordForm) {
                    resetPasswordForm.style.display = 'none';
                    loginFormElement.style.display = 'block';

                    // 清空重置表单
                    document.getElementById('reset-email').value = '';
                    document.getElementById('verify-code').value = '';
                    document.getElementById('new-password').value = '';
                    document.getElementById('confirm-new-password').value = '';
                }
            }

            // 邮箱验证
            const loginForm = document.getElementById('loginForm');
            const loginBtn = document.getElementById('loginBtn');

            loginForm.addEventListener('submit', function(e) {
                const email = document.getElementById('inputEmail').value.trim();
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

                if (!emailRegex.test(email)) {
                    e.preventDefault();
                    showNotification('请输入有效的邮箱地址', 'error');
                    return false;
                }

                // 显示加载状态
                loginBtn.disabled = true;
                loginBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>登录中...';

                return true;
            });

            // 实时邮箱格式验证
            emailInput.addEventListener('blur', function() {
                const email = this.value.trim();
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

                if (email && !emailRegex.test(email)) {
                    this.style.borderColor = '#dc3545';
                    showNotification('邮箱格式不正确，请检查后重新输入', 'error');
                } else {
                    this.style.borderColor = '#e9ecef';
                }
            });

            // 忘记密码功能
            const showResetPassword = document.getElementById('show-reset-password');
            const backToLogin = document.getElementById('back-to-login');
            const loginFormElement = document.querySelector('.auth-form');
            const resetPasswordForm = document.querySelector('.reset-password-form');
            const sendCodeBtn = document.getElementById('send-code-btn');
            const resetEmailInput = document.getElementById('reset-email');
            const resetPasswordBtn = document.getElementById('resetPasswordBtn');

            // 显示重置密码表单
            showResetPassword.addEventListener('click', function(e) {
                e.preventDefault();
                loginFormElement.style.display = 'none';
                resetPasswordForm.style.display = 'block';

                // 清空可能的错误消息
                const errorMessages = resetPasswordForm.querySelectorAll('.alert-danger');
                errorMessages.forEach(msg => msg.style.display = 'none');
            });

            // 返回登录表单
            backToLogin.addEventListener('click', function(e) {
                e.preventDefault();
                showLoginForm();
            });

            // 发送验证码
            sendCodeBtn.addEventListener('click', function() {
                const email = resetEmailInput.value.trim();
                const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

                if (!email) {
                    showNotification('请输入邮箱地址', 'error');
                    return;
                }

                if (!emailRegex.test(email)) {
                    showNotification('请输入有效的邮箱地址', 'error');
                    return;
                }

                // 禁用按钮，开始倒计时
                sendCodeBtn.disabled = true;
                let countdown = 60;

                const timer = setInterval(() => {
                    sendCodeBtn.textContent = `${countdown}秒后重发`;
                    countdown--;

                    if (countdown < 0) {
                        clearInterval(timer);
                        sendCodeBtn.disabled = false;
                        sendCodeBtn.textContent = '发送验证码';
                    }
                }, 1000);

                // 发送验证码逻辑
                const formData = new FormData();
                formData.append('email', email);
                formData.append('type', 'reset');

                fetch('/user/send_verify_code/', {
                    method: 'POST',
                    body: formData,
                    headers: {
                        'X-CSRFToken': getCSRFToken()
                    }
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        showNotification(data.message, 'success');
                    } else {
                        showNotification(data.message, 'error');
                        clearInterval(timer);
                        sendCodeBtn.disabled = false;
                        sendCodeBtn.textContent = '发送验证码';
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    showNotification('发送验证码时发生错误', 'error');
                    clearInterval(timer);
                    sendCodeBtn.disabled = false;
                    sendCodeBtn.textContent = '发送验证码';
                });
            });

            // 重置密码表单提交成功处理
            resetPasswordForm.addEventListener('submit', function(e) {
                const newPassword = document.getElementById('new-password').value;
                const confirmPassword = document.getElementById('confirm-new-password').value;

                if (newPassword !== confirmPassword) {
                    e.preventDefault();
                    showNotification('两次输入的密码不一致', 'error');
                    return false;
                }

                if (newPassword.length < 6) {
                    e.preventDefault();
                    showNotification('密码长度不能少于6位', 'error');
                    return false;
                }

                // 显示加载状态
                resetPasswordBtn.disabled = true;
                resetPasswordBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>重置中...';

                // 添加提交成功后的处理
                const form = this;
                const originalSubmit = form.onsubmit;

                form.onsubmit = function(event) {
                    // 让表单正常提交
                    const result = originalSubmit ? originalSubmit.call(this, event) : true;

                    if (result !== false) {
                        // 表单提交成功后，显示成功消息并切换回登录表单
                        setTimeout(() => {
                            // 检查是否重置成功（通过页面重载后的消息判断）
                            checkResetSuccess();
                        }, 100);
                    }
                    return result;
                };

                return true;
            });

            // 获取CSRF token
            function getCSRFToken() {
                const name = 'csrftoken';
                let cookieValue = null;
                if (document.cookie && document.cookie !== '') {
                    const cookies = document.cookie.split(';');
                    for (let i = 0; i < cookies.length; i++) {
                        const cookie = cookies[i].trim();
                        if (cookie.substring(0, name.length + 1) === (name + '=')) {
                            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                            break;
                        }
                    }
                }
                return cookieValue;
            }

            // 显示通知函数
            function showNotification(message, type = 'info') {
                // 移除现有的通知
                const existingNotification = document.querySelector('.custom-notification');
                if (existingNotification) {
                    existingNotification.remove();
                }

                // 创建通知元素
                const notification = document.createElement('div');
                notification.className = `alert alert-${type === 'error' ? 'danger' : 'success'} custom-notification`;

                const icon = type === 'error' ? 'fa-exclamation-circle' : 'fa-check-circle';
                notification.innerHTML = `<i class="fas ${icon} me-2"></i>${message}`;

                // 添加到页面
                document.body.appendChild(notification);

                // 5秒后移除（成功消息显示时间长一些）
                const displayTime = type === 'success' ? 5000 : 3000;
                setTimeout(() => {
                    notification.style.animation = 'slideOutRight 0.3s ease-in forwards';
                    setTimeout(() => {
                        if (notification.parentNode) {
                            document.body.removeChild(notification);
                        }
                    }, 300);
                }, displayTime);
            }

            // 监听URL变化，处理重置成功后的重定向
            window.addEventListener('load', function() {
                const urlParams = new URLSearchParams(window.location.search);
                const resetSuccess = urlParams.get('reset_success');

                if (resetSuccess === 'true') {
                    showNotification('密码重置成功！请使用新密码登录。', 'success');
                    showLoginForm();

                    // 清除URL参数
                    const newUrl = window.location.pathname;
                    window.history.replaceState({}, document.title, newUrl);
                }
            });
        });


           // 在现有的JavaScript代码中添加QQ登录功能

// QQ登录功能
const qqLoginBtn = document.getElementById('qqLoginBtn');
const qqLoginModal = document.createElement('div');
qqLoginModal.className = 'qq-login-modal';
qqLoginModal.innerHTML = `
    <div class="qq-login-content">
        <div class="qq-login-header">
            <h3>QQ扫码登录</h3>
            <p>请使用QQ扫描下方二维码登录</p>
        </div>

        <div class="qrcode-container">
            <div id="qqLoginQrcode"></div>
        </div>

        <div class="qq-login-status" id="qqLoginStatus"></div>

        <div class="qq-login-footer">
            <p>扫码后请在手机QQ中确认登录</p>
            <p>首次登录将使用QQ邮箱自动注册账号</p>
            <button class="btn-close-modal" id="closeQQModal">取消</button>
        </div>
    </div>
`;

document.body.appendChild(qqLoginModal);

// QQ登录状态
let qqLoginCheckInterval = null;

// 打开QQ登录弹窗
qqLoginBtn.addEventListener('click', function() {
    qqLoginModal.style.display = 'flex';
    initQQLogin();
});

// 关闭QQ登录弹窗
document.getElementById('closeQQModal').addEventListener('click', function() {
    closeQQLoginModal();
});

// 点击弹窗外部关闭
qqLoginModal.addEventListener('click', function(e) {
    if (e.target === qqLoginModal) {
        closeQQLoginModal();
    }
});

function closeQQLoginModal() {
    qqLoginModal.style.display = 'none';
    if (qqLoginCheckInterval) {
        clearInterval(qqLoginCheckInterval);
        qqLoginCheckInterval = null;
    }
}

// 初始化QQ登录
function initQQLogin() {
    const qrcodeContainer = document.getElementById('qqLoginQrcode');
    const statusElement = document.getElementById('qqLoginStatus');

    // 清空状态
    statusElement.style.display = 'none';
    qrcodeContainer.innerHTML = '<div style="text-align: center; padding: 20px;">加载中...</div>';

    // 生成随机的state参数用于安全验证
    const state = generateRandomState();

    // 模拟生成二维码（实际项目中需要调用QQ互联API）
    setTimeout(() => {
        // 这里应该调用QQ互联API获取真实的二维码
        // 由于需要申请QQ互联应用，这里使用模拟流程
        simulateQQLoginFlow(state);
    }, 1000);
}

// 生成随机state
function generateRandomState() {
    return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
}

// 模拟QQ登录流程
function simulateQQLoginFlow(state) {
    const qrcodeContainer = document.getElementById('qqLoginQrcode');
    const statusElement = document.getElementById('qqLoginStatus');

    // 生成模拟二维码（实际项目中应该是QQ互联返回的二维码）
    qrcodeContainer.innerHTML = `
        <div style="text-align: center;">
            <div style="background: #f0f0f0; width: 200px; height: 200px; display: flex; align-items: center; justify-content: center; margin: 0 auto; border-radius: 8px;">
                <div style="text-align: center;">
                    <div style="font-size: 48px; margin-bottom: 10px;">🐧</div>
                    <div style="font-size: 12px; color: #666;">模拟QQ登录二维码</div>
                </div>
            </div>
            <button id="simulateScan" style="margin-top: 15px; background: var(--primary); color: white; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-size: 12px;">
                模拟扫码
            </button>
        </div>
    `;

    // 模拟扫码按钮点击
    document.getElementById('simulateScan').addEventListener('click', function() {
        statusElement.textContent = '扫码成功，正在登录...';
        statusElement.className = 'qq-login-status success';
        statusElement.style.display = 'block';

        // 模拟QQ登录处理
        processQQLogin(state);
    });
}

// 处理QQ登录
function processQQLogin(state) {
    const statusElement = document.getElementById('qqLoginStatus');

    // 模拟获取QQ用户信息（实际项目中需要通过QQ互联API获取）
    const qqUserInfo = {
        openid: 'qq_' + Date.now(),
        nickname: 'QQ用户',
        email: `qq_${Date.now()}@qq.com`, // QQ邮箱格式
        avatar: ''
    };

    // 发送QQ登录请求到后端
    fetch('/user/qq_login/', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRFToken': getCSRFToken()
        },
        body: JSON.stringify({
            openid: qqUserInfo.openid,
            nickname: qqUserInfo.nickname,
            email: qqUserInfo.email,
            avatar: qqUserInfo.avatar,
            state: state
        })
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            statusElement.textContent = '登录成功，正在跳转...';
            statusElement.className = 'qq-login-status success';

            // 登录成功，跳转
            setTimeout(() => {
                if (data.redirect_url) {
                    window.location.href = data.redirect_url;
                } else {
                    window.location.href = '/meet/index/';
                }
            }, 1000);
        } else {
            statusElement.textContent = data.message || '登录失败';
            statusElement.className = 'qq-login-status error';

            // 如果是未注册用户，跳转到注册页面
            if (data.need_register) {
                setTimeout(() => {
                    window.location.href = '/user/register/?qq_email=' + encodeURIComponent(qqUserInfo.email) + '&qq_nickname=' + encodeURIComponent(qqUserInfo.nickname);
                }, 1500);
            }
        }
    })
    .catch(error => {
        console.error('QQ登录错误:', error);
        statusElement.textContent = '登录失败，请重试';
        statusElement.className = 'qq-login-status error';
    });
}
    </script>
</body>
</html>